# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=xpm-nox
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.2.0
pkgrel=7
pkgdesc="X Pixmap library not using X (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="ftp://koala.inria.fr/pub/xpm"
license=("Groupe Bull")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs' '!buildflags' '!makeflags')
source=(ftp://koala.inria.fr/pub/xpm/xpm-nox-${pkgver}.tar.bz2
        xpm-nox-4.2.0-mingw.patch
        001-xpm-nox-4.2.0-mingw-remove-path.patch
        xpm.pc)
sha256sums=('a70f25fc6995b5928a908cb9b73f71a83a6b1ac8e59d367550584326f7a2fd60'
            'e44fc91c46dd4aa5b6af92f64216ff5d7df57206a91ddaaf5cc37b2058bba24e'
            '3b165ca7543ccbcc549c50fd5ee12ba523187f40e29cf906adf603959877c853'
            'f9e8665eb2a3c874ab5814c4b2bd1985d599c5b87da9a87a3ba4d50f3b6e274a')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/xpm-nox-4.2.0-mingw.patch
  patch -p1 -i ${srcdir}/001-xpm-nox-4.2.0-mingw-remove-path.patch
}

build() {
  cp -r "${srcdir}"/${_realname}-${pkgver} "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  make prefix=${MINGW_PREFIX} CC=${MINGW_CHOST}-gcc
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make CC=${MINGW_CHOST}-gcc prefix=${MINGW_PREFIX} DESTDIR="${pkgdir}" install
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig
  cp ${srcdir}/xpm.pc ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/xpm.pc
  sed -e "s|@prefix@|${MINGW_PREFIX}|g" \
      -e "s|@PACKAGE_VERSION@|${pkgver}|g" \
      -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/xpm.pc
}
